package com.ybkj.o2o.zhuanxian.controller.res;

import com.ybkj.o2o.zhuanxian.common.DataGrid;
import com.ybkj.o2o.zhuanxian.common.error.ErrorConstantV4;
import com.ybkj.o2o.zhuanxian.common.error.ResultTransport;
import com.ybkj.o2o.zhuanxian.entity.OrderRefuse;
import com.ybkj.o2o.zhuanxian.manager.OrderRefuseManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("api/orderRefuse")
public class OrderRefuseController {

  @Autowired
  OrderRefuseManager orderRefuseManager;
  
  /**
   * 多条件分页查询拒单记录 .
   * @param orderNo     订单号
   * @param companyId   公司id
   * @param employName  服务人员名字
   * @param startTime   开始时间
   * @param endTime     结束时间
   * @param page        页数 (从1开始)
   * @param rows        每页数量
   * @param appKey      appKey
   */
  @RequestMapping(value = "refuseData", method = RequestMethod.GET)
  @ResponseBody
  public ResultTransport refuseData(
      @RequestParam(required = false, value = "orderNo") String orderNo, 
      @RequestParam(required = false, value = "companyId") Long companyId,
      @RequestParam(required = false, value = "employName") String employName,
      @RequestParam(required = false, value = "startTime") Long startTime,
      @RequestParam(required = false, value = "endTime") Long endTime, 
      @RequestParam(required = false, value = "page") Integer page,
      @RequestParam(required = false, value = "rows") Integer rows,
      @RequestParam("appKey") String appKey) {
    ResultTransport response = null;
    try {
      Date start = null;
      Date end = null;
      if (startTime != null) {
        start = new Date(startTime);
      }
      if (endTime != null) {
        end = new Date(endTime);
      }
      DataGrid<OrderRefuse> orders =
          orderRefuseManager.findByParams(companyId, orderNo, employName, start, end, page, rows,
              appKey);
      response = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
      response.setData(orders);
    } catch (Exception ex) {
      ex.printStackTrace();
      response = ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
    return response;
  }


}
